<?php

namespace App\Admin\Controllers;

use App\crm_route;
use Encore\Admin\Form;
use Encore\Admin\Grid;
use Encore\Admin\Layout\Column;
use Encore\Admin\Layout\Row;
use Encore\Admin\Facades\Admin;
use Encore\Admin\Layout\Content;
use App\Http\Controllers\Controller;
use Encore\Admin\Widgets\Box;
use Encore\Admin\Controllers\ModelForm;
use Encore\Admin\Tree;
class Crm_routeController extends Controller
{
    use ModelForm;
    // 旅游线路控制器
    /**
     * Index interface.
     *
     * @return Content
     */
    public function index()
    {
        return Admin::content(function (Content $content) {

            $content->header('线路管理');
            $content->description('线路列表');
            // $content->row(function (Row $row) {
            //     $row->column(6, crm_route::tree());
            //     $row->column(6, $this->form());
            // });
            $content->body(crm_route::tree());
        });
        // return Admin::content(function (Content $content) {

        //     $content->header('线路管理');
        //     $content->description('线路列表');

        //     $content->body($this->grid());
        // });
    }

    /**
     * Edit interface.
     *
     * @param $id
     * @return Content
     */
    public function edit($id)
    {
        return Admin::content(function (Content $content) use ($id) {

            $content->header('线路管理');
            $content->description('线路列表');

            $content->body($this->form()->edit($id));
        });
    }

    /**
     * Create interface.
     *
     * @return Content
     */
    public function create()
    {
        return Admin::content(function (Content $content) {

            $content->header('线路管理');
            $content->description('线路添加');

            $content->body($this->form());
        });
    }

    /**
     * Make a grid builder.
     *
     * @return Grid
     */
    protected function grid()
    {
        return Admin::grid(crm_route::class, function (Grid $grid) {

            $grid->disableExport();
            // $grid->disableFilter();
            // $grid->id('序号')->sortable();
            $grid->route_name('线路名称');
            $grid->route_price('线路价格');
            $grid->filter(function ($filter) {
                $filter->useModal();
                $filter->like('route_name','线路名称');
                $filter->like('route_price','线路价格');
            });
            // $grid->created_at();
            // $grid->updated_at();
        });
    }

    /**
     * Make a form builder.
     *
     * @return Form
     */
    protected function form()
    {
        return Admin::form(crm_route::class, function (Form $form) {
            $list=crm_route::all()->pluck('order','title');
            $form->select('parent_id', '父级线路')->options(crm_route::selectOptions());
            // $form->display('id', '序号');
            $form->text('title','标题')->rules('required');
            $form->tools(function (Form\Tools $tools) {
                // 去掉跳转列表按钮
                $tools->disableListButton();
            });
           
            // $form->display('created_at', 'Created At');
            // $form->display('updated_at', 'Updated At');
        });
    }
}
